Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.3
-
None
Description
WHAT:
When a lambda captures local variables, these are copied into the lambda frame and behave as local variables within the lambda's scope. It would be convenient to alter this so that captured variables could be made read-only and reject side-effect operators at parsing time.
WHY:
This is an element of surprise for users with a Java background since captured variables must be final. It is also surprising when users expect dynamic (non lexical) scoping and would expect side effects to be carried thru scopes.
The examples below illustrates the 2 ways this can be surprising.
let x = -42; const f = y -> x += y; // x is implicitly declared as a copy in the lambda 'f' frame f(42); // x is still -42
HOW:
By introducing a new feature flag aptly named 'constCapture'. This feature flag determines whether captured variables are const or not (default).
Attachments
Issue Links
- is related to
-
JEXL-413 Allow const capture runtime option
- Resolved